/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import requeteur.Paragraphe;
import requeteur.Resultat;
import requeteur.ResultatCollection;
import requeteur.TermOccurReq;
import requeteur.TermeReq;

/**
 *
 * @author Cyril
 */
public class RIModel {
    
    private DBWriter db;
    private TermesCollection termes;
    private NoeudsCollection nodes;
    private DocumentsCollection docs;
    private int currentDocumentId;
    private int currentNodeId;
    private TermeReq trmReq;
    
    private Document currentDocument;
    private Noeud currentNode;
    
    
    public RIModel() {
        this.db = new DBWriter();
        this.termes = new TermesCollection();
        this.nodes = new NoeudsCollection();
        this.docs = new DocumentsCollection();
    }
    
    public void addDocument(String name) {
        this.currentDocumentId = docs.addDocument(name);
    }
    
    public void addNode(String name, String xpath) {
        //TODO !!!
        //récupérer le doc courant pour l'insérer en attribut du noeud
        this.currentNode = nodes.addNoeud(name, xpath, currentDocumentId);
    }
    
    public int getCurrentNodeId(){
        return this.currentNodeId;
    }
    
    public void addTerme(String terme, int pos) {
        //TODO !!!
        //récupérer le noeud courant pour l'insérer en attribut du terme
        
        this.termes.addTermeOccur(terme, this.currentNode, pos);
    }
    
    public Terme getTermeFromTC(String word){
        return this.termes.getTermeFromHM(word);
    }
    
    public void updateDB() {
        this.db.resetDB();
        this.db.updateDocumentsWithPacketLimit(docs.getListValues());
        this.db.updateNoeudsWithPacketLimit(nodes.getListValues());
        this.db.updateTermesWithPacketLimit(termes.getListValues());
    }
    
    public ArrayList<Terme> getListTermes(){
        return termes.getListTermes();
    }
    
    private void calculPoids() {
        //TODO
    }
    
    public TermeReq addTermereq(String mot){
        return this.db.getTermeReqFromBDD(mot);
    }

    public ArrayList<Resultat> addResult(ArrayList<Paragraphe> listparagraphe){
        return this.db.getResultWithListIdPara(listparagraphe);
    }
    
    public ResultatCollection getListResult(){
        return this.db.getListResult();
    }
}
